﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class sysadmin_CountManager_Project :PowerCreator.LMS.Web.Base.BasePage
{
    PowerCreator.LMS.Web.Project.NewProjectPlan opProjectPlan = new PowerCreator.LMS.Web.Project.NewProjectPlan();
    PowerCreator.LMS.Web.Project.Project opProject = new PowerCreator.LMS.Web.Project.Project();
    PowerCreator.LMS.ViewQuery.ViewQuery opViewQuery = new PowerCreator.LMS.ViewQuery.ViewQuery();

    string _cmd1 = "select count(*) from TStudentPassProjectLog where FKSpplogTrainproID={0}";   //查询总人数
    string _cmd2 = "select count(*) from TStudentPassProjectLog where FKSpplogTrainproID={0} and SpplogState=16";  //通过人数
    string _cmd3 = "select count(*) from TStudentPassProjectLog where FKSpplogTrainproID={0} and SpplogState=17";  //未通过人数

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitPage();

            string search = GetSearch();
            BinderPager(search);
            BinderRPT(search,1);
        }
    }
    protected override void InitPage()
    {
        base.InitPage();
    }
    private string GetSearch()
    {
        string search = "";
        return search;
    }
    private void BinderPager(string search)
    {
        AspNetPager1.PageSize = LMSPageSize;
        AspNetPager1.RecordCount = opProject.QueryTrainProjectCount(search);
    }
    private void BinderRPT(string search,int pageIndex)
    {
        DataTable dt = opProject.QueryTrainProject(search, LMSPageSize, pageIndex);
        dt.Columns.Add("ProjectStudentCount1"); //总学习人数
        dt.Columns.Add("ProjectStudentCountYes1"); //通过人数
        dt.Columns.Add("ProjectStudentCountNo1");   //未通过人数
        string cmd1, cmd2, cmd3;
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            cmd1 = string.Format(_cmd1, dt.Rows[i]["TrainproID"]);
            cmd2 = string.Format(_cmd2, dt.Rows[i]["TrainproID"]);
            cmd3 = string.Format(_cmd3, dt.Rows[i]["TrainproID"]);
            dt.Rows[i]["ProjectStudentCount1"] = opViewQuery.Query(cmd1, 1, 1).Rows[0][0];
            dt.Rows[i]["ProjectStudentCountYes1"] = opViewQuery.Query(cmd2, 1, 1).Rows[0][0];
            dt.Rows[i]["ProjectStudentCountNo1"] = opViewQuery.Query(cmd3, 1, 1).Rows[0][0];

            if (string.IsNullOrEmpty(dt.Rows[i]["ProjectStudentCount1"].ToString()))
            {
                dt.Rows[i]["ProjectStudentCount1"] = "0";
            }
            if (string.IsNullOrEmpty(dt.Rows[i]["ProjectStudentCountYes1"].ToString()))
            {
                dt.Rows[i]["ProjectStudentCountYes1"] = "0";
            }
            if (string.IsNullOrEmpty(dt.Rows[i]["ProjectStudentCountNo1"].ToString()))
            {
                dt.Rows[i]["ProjectStudentCountNo1"] = "0";
            }
        }

        rpt_Project.DataSource = dt;
        rpt_Project.DataBind();
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderRPT(search, AspNetPager1.CurrentPageIndex);
    }
    protected void rpt_Project_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName.ToString() == "ldetail")
        {
            string url = "ProjectDetail.aspx?ProjectID=" + e.CommandArgument.ToString();
            PowerCreator.LMS.Common.Script.Script.RedirectURL(url);
        }
    }
}
